<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
    <link rel="stylesheet" type="text/css" href="../css/aui-flex.css" />
    <style>
    </style>
</head>
<style>
    .home:before {
        content: url(../image/home.png);
    }

    .refresh:before {
        content: url(../image/refresh.png);
    }

    .company:before {
        content: url(../image/company.png);
    }

    .pa-title {
        font-size: 17px;
        color: black;
        font-weight: bold;
    }

    .pa-title-content {
        font-size: 17px;
        color: black;
    }

    body {
        background-color: #D9D8DB;
    }

    .pa_sglg_t {
        background-color: #254060;
        height: 377px;
        color: white;
        overflow: auto;
    }

    .pa_sglg_but {
        height: 58px;
        line-height: 58px;
        float: left;
        width: 150px;
        font-size: 30px;
        color: white;
        text-align: center;
        margin-left: 50px;
    }

    .pa_sglgProd {
        font-size: 15px;
        float: left;
        height: 58px;
        line-height: 58px;
        text-align: center;
        margin-left: 5px;
    }

    p {
        font-size: 17px;
        color: black;
        font-weight: bold;
        text-align: center;
    }

    table {
        width: 100%;
        table-layout: fixed;
        word-wrap: break-word;
    }

    td {
        white-space: nowrap;
        text-overflow: ellipsis;
        overflow: hidden;
    }
</style>

<body>
    <header class="aui-bar aui-bar-nav" style="background-color: #D9D8DB">
        <div style="width: 10%;height: 60px;float: left;padding-top: 6px;">
            <a class="aui-pull-left aui-btn ">
                <span class="aui-iconfont company"></span>
            </a>
        </div>
        <div style="width: 10%;height: 60px;float: left;">
            <div style="text-align: left;">
                <span class="pa-title">富晟安创</span>
            </div>
        </div>
        <div style="width: 70%;height: 60px;float: left;">
            <div style="width:18%; float: left; text-align: left;">
                <span class="pa-title-content" id="locationName"></span>
            </div>
            <div style="width:18%; float: left; text-align: left;">
                <span class="pa-title-content" id="workCenterName"></span>
            </div>
            <div style="width:24%; float: left; text-align: left;">
                <span class="pa-title-content" id="workCellName"></span>
            </div>
            <div style="width:40%; float: left; text-align: left;">
                <span class="pa-title-content" id="nowDate"></span>
            </div>
        </div>
        <div style="width: 5%;height: 50px;float: left;">
            <a class="aui-pull-right aui-btn " onclick="refresh()">
                <span class="aui-iconfont refresh"></span>
            </a>
        </div>
        <div style="width: 5%;height: 50px;float: left;">
            <a class="aui-pull-right aui-btn" onclick="closeWin()">
                <span class="aui-iconfont home"></span>
            </a>
        </div>
    </header>
    <div class="aui-content">
        <div class="aui-flex-col aui-flex-center" style="height: 30px;">
            <div class="aui-flex-item-12">
                <p id="titleConten"></p>
            </div>
        </div>
        <div class="aui-flex-col aui-flex-center">
            <div class="aui-flex-item-12" style="margin-left: 25%;">
                <div class="pa_sglg_but" style="background-color: green;" onclick="save()">提交
                </div>
                <div class="pa_sglg_but" style="background-color: red;" onclick="cancle()">
                    关闭
                </div>
            </div>
        </div>

        <div class="aui-flex-col aui-flex-center" style="margin-top: 1%;">
            <div class="aui-flex-item-12">
                <div class="aui-flex-col pa_sglg_t">
                    <div class="aui-flex-item-12">
                        <div style="height: 100%;width: 100%;">
                            <table class="table" border="1px solid gray" cellspacing="0" cellpadding="0">
                                <thead>
                                    <tr style="text-align: center;color: white;font-size: 20px;">
                                        <td algin='center' style="width:8%">
                                            <input name='main' type='checkbox' id="allboxs" onclick="allcheck()" />
                                        </td>
                                        <td algin='center' style="width:10%">序号</td>
                                        <td algin='center' style="width:21%">人员编码</td>
                                        <td algin='center' style="width:21%">人员名称</td>
                                        <td algin='center' style="width:20%">工号</td>
                                        <td algin='center' style="width:20%">班组</td>
                                    </tr>
                                </thead>
                                <tbody id="employeeDataHtml">
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript">

    var equipUniqueId = "";

    //初始化
    apiready = function () {
        //获取设备唯一号
        equipUniqueId = localStorage.getItem('equipUniqueId');
        //产线工位信息
        document.getElementById("locationName").innerHTML = api.pageParam.locationName;
        document.getElementById("workCenterName").innerHTML = api.pageParam.workCenterName;
        document.getElementById("workCellName").innerHTML = api.pageParam.workCellName;
        document.getElementById("nowDate").innerHTML = getTimeCommon();
        //当前时间刷新
        window.setInterval("getTime()", 1000);

        //上岗
        if (api.pageParam.flag == 1) {
            document.getElementById("titleConten").innerHTML = "产线人员上岗";

        } else if (api.pageParam.flag == 2) {
            document.getElementById("titleConten").innerHTML = "产线人员离岗";
        }

        //查询记录  上岗则查这个班组未上岗的人员。离岗查询已上岗的人员
        doSearch();
    }

    //时间刷新
    function getTime() {
        document.getElementById("nowDate").innerHTML = getTimeCommon();
    }

    //查询上岗信息
    function doSearch() {
        var workCellCode = "";
        //是否按工位上岗查询：0否，1是
        var cjFlag = api.pageParam.cjFlag;
        if ("1" == cjFlag) {
            workCellCode = api.pageParam.workCellCode;
        }
        var proddate = $("#prodDate").val();
        var teamCode = $("#teamCode").val();
        var shiftCode = $("#shiftCode").val();
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getAssemblySearchEmployeeData";
        var data = {
            values: {
                workCenterCode: api.pageParam.workCenterCode,
                workCellCode: workCellCode,
                proddate: api.pageParam.proddate,
                teamCode: api.pageParam.teamCode,
                shiftCode: api.pageParam.shiftCode,
                flag: api.pageParam.flag,
                un: un,
            }
        };
        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';

        ajaxForData(params, data, false, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");

                //成功
                if (myobj.code == 0) {

                    //班組賦值
                    var list = eval(myobj.list);
                    var html = "";
                    //遍历
                    for (var i = 0; i < list.length; i++) {
                        html += "<tr style='text-align: center;color: white;font-size: 14px;height:40px;'>";
                        html += "<td><input name='sub' type='checkbox' /></td>";
                        html += "<td name='index'>" + (i + 1) + "</td>";
                        html += "<td name='empCode'>" + list[i].empCode + "</td>";
                        html += "<td name='empName'>" + list[i].empName + "</td>";
                        html += "<td name='empNo'>" + list[i].empNo + "</td>";
                        html += "<td name='teamName'>" + list[i].teamName + "</td>";
                        html += "</tr>";
                    }

                    $api.html($api.byId("employeeDataHtml"), html);
                } else {
                    $api.html($api.byId("employeeDataHtml"), "");
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            } else {
                alert("网络连接超时!")
            }
        });
    }

    function allcheck() {
        var nn = $("#allboxs").is(":checked"); //判断th中的checkbox是否被选中，如果被选中则nn为true，反之为false
        if (nn == true) {
            var namebox = $("input[name^='sub']");  //获取name值为boxs的所有input
            for (i = 0; i < namebox.length; i++) {
                namebox[i].checked = true;    //js操作选中checkbox
            }
        }
        if (nn == false) {
            var namebox = $("input[name^='sub']");
            for (i = 0; i < namebox.length; i++) {
                namebox[i].checked = false;
            }
        }
    }

    //上岗/离岗保存
    function save() {

        //选中数据
        var check = $("input[name='sub']:checked");
        var count = 0;
        var empNo = "";
        var empNoStr = "";
        check.each(function () { //遍历
            var row = $(this).parent("td").parent("tr");
            empNo = row.find("[name='empNo']").html();
            count++;

            if (empNoStr == "") {
                empNoStr += empNo;
            } else {
                empNoStr += "," + empNo;
            }
        });

        if (count == 0) {
            api.toast({
                msg: "请选择至少一条表格数据",
                duration: 3000
            });
            return;
        }

        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getAssemblyTakeQuitPostZSSave";
        var data = {
            values: {
                proddate: api.pageParam.proddate,
                workCenterCode: api.pageParam.workCenterCode,
                workCellCode: api.pageParam.workCellCode,
                teamCode: api.pageParam.teamCode,
                shiftCode: api.pageParam.shiftCode,
                flag: api.pageParam.flag,
                empNoStr: empNoStr,
                sgFlag: api.pageParam.sgFlag,//上岗标识：0刷卡，1勾选
                cjFlag: api.pageParam.cjFlag,//是否按工位上岗查询：0否，1是
                un: un
            }
        };

        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';

        api.showProgress({
            title: '保存中...',
        });

        ajaxForData(params, data, false, function (ret, err) {
            if (ret) {
                api.hideProgress();
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //成功
                if (myobj.code == 0) {
                    api.toast({
                        msg: "保存成功!",
                        duration: 3000
                    });

                    //返回上级页面
                    cancle();
                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            } else {
                api.hideProgress();
                alert("网络连接超时!")
            }
        });
    }

    //刷新按钮
    function refresh() {

        //获取设备唯一号
        equipUniqueId = localStorage.getItem('equipUniqueId');

        //上岗离岗记录信息
        doSearch();
    }

    //取消,返回上一级
    function cancle() {
        api.closeWin({});
        api.execScript({
            name: 'productionAssemblySglg',
            script: 'refresh()'
        });
    }

    //返回按钮
    function closeWin() {
        api.closeToWin({ name: api.pageParam.rootName });
        api.execScript({
            name: api.pageParam.rootName,
            script: 'refresh()'
        });
    }
</script>

</html>